<template>
  <div class="category">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="分类">
        <el-input v-model="formInline.user" placeholder="分类"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handerDrawer('添加目标')"
          >添加</el-button
        >
      </el-form-item>
    </el-form>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="planName" label="目标名称"> </el-table-column>
      <el-table-column prop="planType" label="目标分类"> </el-table-column>
      <el-table-column prop="planAmount" label="目标金额"> </el-table-column>
      <el-table-column prop="createTime" label="开始时间"> </el-table-column>
      <el-table-column prop="endTime" label="结束时间"> </el-table-column>
      <el-table-column prop="remark" label="备注"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-drawer
      :title="drawerTitle"
      :visible.sync="drawer"
      direction="rtl"
      :before-close="handleClose"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="目标名称">
          <el-input v-model="form.classifyName"></el-input>
        </el-form-item>
        <el-form-item label="目标分类">
          <el-input v-model="form.classifyName"></el-input>
        </el-form-item>
        <el-form-item label="目标金额">
          <el-input v-model="form.classifyName"></el-input>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-input v-model="form.classifyName"></el-input>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-input v-model="form.classifyName"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="form.remark"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handerAdd" plain>
            {{ drawerTitle }}
          </el-button>
        </el-form-item>
        <el-form-item v-show="drawerTitle == '修改记录'">
          <el-button type="danger" @click="handerAdd" plain>
            删除记录
          </el-button>
        </el-form-item>
      </el-form>
    </el-drawer>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formInline: {
        user: "",
        region: "",
      },
      drawer: false,
      tableData: [
        {
          userId: "1", //用户ID
          planName: "3月支出计划", //目标名称
          planType: "支出", //目标分类
          planAmount: "2000", //目标金额
          createTime: "2023-03-02", //开始时间
          endTime: "2023-03-01", //结束时间
          remark: "加油", //备注
        },
        {
          userId: "1", //用户ID
          planName: "4月支出计划", //目标名称
          planType: "支出", //目标分类
          planAmount: "2000", //目标金额
          createTime: "2023-03-02", //开始时间
          endTime: "2023-03-01", //结束时间
          remark: "加油", //备注
        },
        {
          userId: "1", //用户ID
          planName: "5月支出计划", //目标名称
          planType: "支出", //目标分类
          planAmount: "2000", //目标金额
          createTime: "2023-03-02", //开始时间
          endTime: "2023-03-01", //结束时间
          remark: "加油", //备注
        },
        {
          userId: "1", //用户ID
          planName: "6月支出计划", //目标名称
          planType: "支出", //目标分类
          planAmount: "2000", //目标金额
          createTime: "2023-03-02", //开始时间
          endTime: "2023-03-01", //结束时间
          remark: "加油", //备注
        },
        {
          userId: "1", //用户ID
          planName: "7月支出计划", //目标名称
          planType: "支出", //目标分类
          planAmount: "2000", //目标金额
          createTime: "2023-03-02", //开始时间
          endTime: "2023-03-01", //结束时间
          remark: "加油", //备注
        },
        {
          userId: "1", //用户ID
          planName: "8月支出计划", //目标名称
          planType: "支出", //目标分类
          planAmount: "2000", //目标金额
          createTime: "2023-03-02", //开始时间
          endTime: "2023-03-01", //结束时间
          remark: "加油", //备注
        },
      ],
      drawer: false,
      form: {
        classifyName: "",
        remark: "",
      },
      drawerTitle: "",
    };
  },

  methods: {
    handerDrawer(item) {
      this.drawer = true;
      this.drawerTitle = item;
    },
    onSubmit() {
      console.log("submit!");
    },
    handleClick(row) {
      console.log(row);
    },
    handerAdd() {
      this.$message({
        message: "成功",
        type: "success",
      });
      this.drawer = false;
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
  },
};
</script>





<style scoped>
.category {
  padding: 20px 40px;
}
.category-header {
  padding: 20px 40px;
}
.category-header__left .el-card {
  width: 200px;
  border: 0px;
}
.el-card.is-always-shadow {
  float: right;
}
.like {
  cursor: pointer;
  font-size: 25px;
  display: inline-block;
}
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}
.el-row {
  padding-bottom: 40px;
  border-bottom: 1px solid #f2eff5;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 480px;
}
</style>